import 'package:flutter/material.dart';
import './page/each_page.dart';

class BottomAppBarWidget extends StatefulWidget {
  const BottomAppBarWidget({Key? key}) : super(key: key);

  @override
  _BottomAppBarWidgetState createState() => _BottomAppBarWidgetState();
}

class _BottomAppBarWidgetState extends State<BottomAppBarWidget> {
  int _currentindex = 0;
  List<Widget> list = [];

  @override
  void initState() {
    list..add(EachPage(title: 'Home',))..add(EachPage(title: 'Me',));
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: list[_currentindex],
      // 浮动按钮
      floatingActionButton: FloatingActionButton(
        onPressed: () { 
          Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context){
            return EachPage(title: 'New page');
          }));
        },
        tooltip: '添加',
        child: Icon(Icons.add, color: Colors.white),
      ),
      // 图标位置
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      bottomNavigationBar: BottomAppBar(
        color: Theme.of(context).primaryColor,
        // 形状
        shape: CircularNotchedRectangle(),
        child: Row(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            IconButton(
              onPressed: () {
                setState(() {
                  _currentindex = 0;
                });
              },
              icon: Icon(Icons.home),
              color: Colors.white,
            ),
            IconButton(
              onPressed: () {
                setState(() {
                  _currentindex = 1;
                });
              },
              icon: Icon(Icons.airport_shuttle),
              color: Colors.white,
            )

          ],
        ),
      ),
    );
  }
}
